﻿using RestSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _006_VideoDownload
{
    public class HttpHelper
    {
        public static string Get(string url)
        {
            var client = new RestClient(url);
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("User-Agent", "PostmanRuntime/7.24.1");
            request.AddHeader("Accept", "*/*");
            request.AddHeader("Accept-Encoding", "gzip, deflate, br");
            request.AddHeader("Connection", "keep-alive");
            IRestResponse response = client.Execute(request);

            int responseCount = 20;
            while (string.IsNullOrEmpty(response.Content))
            {
                response = client.Execute(request);
                responseCount--;
                if(responseCount < 0)
                {
                    break;
                }
            }

            //Console.WriteLine(response.Content);
            return response.Content;
        }
    }
}
